<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>账户项目后台管理系统</title>
    <meta name="keywords" content="账户项目后台管理系统">
    <meta name="description" content="账户项目后台管理系统">

    <link rel="shortcut icon" href="/favicon.ico">

    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/font-awesome.min.css" rel="stylesheet">
    <link href="/css/animate.min.css" rel="stylesheet">
    <link href="/css/style.min.css" rel="stylesheet">
<style type="text/css">
.has-success .text-danger{color: #1ab394;}
</style>

</head>
<body class="gray-bg">

    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">

                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>修改密码</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t pass-form" id="commentForm" >
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><span class="text-danger">*&nbsp;</span>原密码：</label>
                                <div class="col-sm-5">
                                    <input id="original_password" name="oldPassword" class="form-control" type="password">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><span class="text-danger">*&nbsp;</span>新密码：</label>
                                <div class="col-sm-5">
                                    <input id="password" name="kdsLoginPwd" class="form-control" type="password">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><span class="text-danger">*&nbsp;</span>确认新密码：</label>
                                <div class="col-sm-5">
                                    <input id="confirm_password" name="confirm_password" class="form-control" type="password">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3">
                                    <button class="btn btn-primary" type="submit">保存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>


            </div>
        </div>
    </div>

    <!-- jQuery Validation plugin javascript-->
    <script src="/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="/js/plugins/validate/messages_zh.min.js"></script>

<script type="text/javascript">
    
    
//以下为修改jQuery Validation插件兼容Bootstrap的方法，没有直接写在插件中是为了便于插件升级
$.validator.setDefaults({
    highlight: function (element) {
        $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
    },
    success: function (element) {
        element.closest('.form-group').removeClass('has-error').addClass('has-success');
    },
    errorElement: "span",
    errorPlacement: function (error, element) {
        if (element.is(":radio") || element.is(":checkbox")) {
            error.appendTo(element.parent().parent().parent());
        } else {
            error.appendTo(element.parent());
        }
    },
    errorClass: "help-block m-b-none",
    validClass: "help-block m-b-none"

});

//以下为官方示例
$().ready(function () {
    // validate signup form on keyup and submit
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#commentForm").validate({
        rules: {
            oldPassword: {
                required: true,
                minlength: 5
            },
            kdsLoginPwd: {
                required: true,
                minlength: 5
            },
            confirm_password: {
                required: true,
                minlength: 5,
                equalTo: "#password"
            }
        },
        messages: {
            oldPassword: {
                required: icon + "请输入您的原密码",
                minlength: icon + "密码必须5个字符以上"
            },
            kdsLoginPwd: {
                required: icon + "请输入您的新密码",
                minlength: icon + "密码必须5个字符以上"
            },
            confirm_password: {
                required: icon + "请再次输入新密码",
                minlength: icon + "密码必须5个字符以上",
                equalTo: icon + "两次输入的密码不一致"
            }
        },
        submitHandler:function(){
            $.ajax({
                type        :    'post',
                url         :    "update-password",
                dataType    :    'json',
                async       :    false,
                cache       :    false,
                processData :    false,  // 告诉jQuery不要去处理发送的数据
                contentType :    false,  // 告诉jQuery不要去设置Content-Type请求头
                data        :    new FormData($(".pass-form")[0]),
                success     :    function(msg){
                    if (msg.code!= 20000) {
                        alert(msg.message);
                    }else{
                        alert(msg.message);
                        window.location.href='logout';
                    }
                }
            });
        }
    });
});
$.validator.setDefaults({
    /*submitHandler: function() {
      alert("提交事件!");
    }*/
});

</script>


</body>
</html>
